package com.jiyun.service.impl;

import com.alibaba.cloud.commons.lang.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jiyun.mapper.*;
import com.jiyun.model.*;
import com.jiyun.service.CourseService;
import com.jiyun.service.RaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

import static com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.Prefix.one;


/* *
 * @Author nxj
 * @Date 2023 08 2023/8/4 10 43
 * */
@Service
public class RaceServiceImpl extends ServiceImpl<RaceMapper, Race> implements RaceService {

    @Autowired
    private RaceUserMapper raceUserMapper;
    @Autowired
    private LabelMapper labelMapper;


    @Override
    public String selectLable(Integer integer) {
        LambdaQueryWrapper<Label> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Label::getId, integer);
        Label label = labelMapper.selectOne(lambdaQueryWrapper);
        return label.getLname();
    }

    @Override
    public void toBao(Integer id, Integer uid, Integer tid) {
        LambdaQueryWrapper<RaceUser> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(RaceUser::getRid,id);
        lambdaQueryWrapper.eq(RaceUser::getTid,tid);
        RaceUser user = raceUserMapper.selectOne(lambdaQueryWrapper);
        if (user!=null){
            user.setUid(user.getUid()+","+uid);
            raceUserMapper.updateById(user);
        }else {
            RaceUser user1 = new RaceUser();
            user1.setRid(id);
            user1.setUid(uid.toString());
            user1.setTid(tid);
            user1.setState(1);
            raceUserMapper.insert(user1);
        }
    }
}